cmake_minimum_required(VERSION 3.22)
project(ABCKIT_WRAPPER)

set(CMAKE_CXX_STANDARD 17)

set(TEST_TARGET abckit_wrapper_test)

set(LIB_ARCH clang_x64)
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
    set(LIB_ARCH mingw_x86_64)
    add_definitions(-DPANDA_TARGET_WINDOWS)
endif ()

message("LIB_ARCH:${LIB_ARCH}")

set(ARK_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../../..)
set(THIRD_PART_PATH ${ARK_ROOT}/third_party)

# google test
if (NOT TARGET gtest)
    set(GOOGLE_TEST_PATH ${THIRD_PART_PATH}/googletest)
    include_directories(${GOOGLE_TEST_PATH}/googletest/include)
    add_subdirectory(${GOOGLE_TEST_PATH} ${CMAKE_CURRENT_BINARY_DIR}/googletest)
endif ()

# bounds_checking_function
include_directories(${THIRD_PART_PATH}/bounds_checking_function/include)
file(GLOB SRC_SEC_STATIC ${THIRD_PART_PATH}/bounds_checking_function/src/*.c)
add_library(sec_static ${SRC_SEC_STATIC})

# libabckit
add_definitions(-DABCKIT_USE_EXCEPTIONS)
set(LIBABCKIT_SRC_ROOT ${ARK_ROOT}/arkcompiler/runtime_core/libabckit)
set(LIBABCKIT_LIB_PATH ${ARK_ROOT}/out/x64.debug/arkcompiler/runtime_core)
set(THIRD_PARTY_LIB_PATH ${ARK_ROOT}/out/x64.debug/thirdparty/zlib)
include_directories(${LIBABCKIT_SRC_ROOT}/include)
link_directories(${LIBABCKIT_LIB_PATH})

# copy libs
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
    file(GLOB LIBABCKIT_LIBS ${LIBABCKIT_LIB_PATH}/*.dll)
else ()
    file(GLOB LIBABCKIT_LIBS ${LIBABCKIT_LIB_PATH}/*.so)
    file(GLOB THIRD_PARTY_LIBS ${THIRD_PARTY_LIB_PATH}/*.so)
    LIST(APPEND LIBABCKIT_LIBS ${THIRD_PARTY_LIBS})
endif ()
file(COPY ${LIBABCKIT_LIBS} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})

# abckit_wrapper
include_directories(include)
file(GLOB SRC_ABCKIT_WRAPPER library/*.cpp)
add_library(abckit_wrapper STATIC ${SRC_ABCKIT_WRAPPER})
target_link_libraries(abckit_wrapper abckit sec_static)

# test
add_definitions(-DABCKIT_WRAPPER_ABC_FILE_DIR="${CMAKE_CURRENT_SOURCE_DIR}/tests/build/")

# abckit_wrapper_test
include_directories(tests/mock/include)
include_directories(tests/util/include)
file(GLOB_RECURSE SRC_TEST
        tests/mock/*.cpp
        tests/ut/*.cpp
        tests/util/*.cpp
        tests/main.cpp
)

add_executable(${TEST_TARGET} ${SRC_TEST})

target_link_libraries(
        ${TEST_TARGET}
        abckit
        abckit_wrapper
        gtest
        gmock
        sec_static
)